<?php

function set_key_to_value($array){
    $result =array();
    foreach ($array as $value){
        $result[$value]=$value;
    }
    return $result;
}

function restaurant_user_insert(&$edit, $account, $category){
    $restaurant_checkbox= $account->field_restaurant['und'][0]['value'];
    if($restaurant_checkbox ==1){
        $account->roles[4]='restaurant';
    }
   
}

function restaurant_user_role(){
    global $user;
    foreach($user->roles as $role){
        switch ($role){
            case "administrator" :return true; break;
            case "authenticated user" : return true; break;
        }
    }
    return false;   
}

function resturant_restaurant_user_role(){
    global $user;
    foreach($user->roles as $role){
        switch ($role){
            case "administrator" :return true; break;
            case "restaurant" : return true; break;
        }
    }
    return false;
}

function restaurant_get_restaurants_names(){
     global $user;
     $query = db_select('ep_restaurants', 'r')
            ->distinct();
     $query->fields('r',array('rid','name'));
     $query->condition('uid',$user->uid,'=');
     $result = $query->execute();
     $restaurants =array();
     foreach ($result as $restaurant) {
         $restaurants[$restaurant->rid] =$restaurant->name ;
     }
     return $restaurants;
}


function get_restaurant_city(){
     $query = db_select('ep_restaurants', 'r')
            ->distinct();
     $query->fields('r',array('city'));
     $result = $query->execute();
     $varosok =array();
     foreach ($result as $restaurant) {
         $varosok[] = $restaurant->city;
     }
     return $varosok;
}


function restaurant_get_restaurants_name_form(){
        $temp = get_restaurant_city();
        $cities = set_key_to_value($temp);
        $form['city'] = array(
            '#type' => 'select',
            '#title' => t('Válasz várost!'),
            '#options' => $cities);
        $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Save'),
        );
        
        return $form;
}

function restaurant_get_restaurants_name_form_submit($form, &$form_values){
    drupal_set_message($form_values["values"]["city"]." nevű városok listázva.");
    $_SESSION['varos']= $form_values["values"]["city"];
}

